
import java.io.InputStream;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;

/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
/**
 *
 * @author HP
 */
public class AudioService {

    private String nameOfResource;
    Player player;

    public AudioService(String nameOfResource) {
        this.nameOfResource = nameOfResource;
    }

    public void playFromResource() {
        try {
            InputStream in = getClass().getResourceAsStream("/" + this.nameOfResource);
            player = Manager.createPlayer(in, "audio/x-wav");
            player.start();
        } catch (Exception e) {
            return;
        }


    }

    public void stop() {
        if (player!=null) {
            try {
                player.stop();
                System.out.println("Stop");
            } catch (MediaException ex) {
                ex.printStackTrace();
            }
        }
    }
    
    public void Start()
    {
        if (player.getState() == Player.STARTED) {
            try {
                player.stop();
            } catch (MediaException ex) {
                ex.printStackTrace();
            }
        }
    }
    
    public void isStop()
    {
    }
    
}
